<template>
  <div class="auto form-horizontal" >
    <modal :show.sync="show"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h3 style="color:black" class="modal-title">其他收费发票</h3>
      </header>
      <article  slot="modal-body" style = "padding-bottom:10px;  display: flex; justify-content: center;">
        <div class="row" v-if="logic.f_charge_type[0] === '国税发票'" id="testbill">
          {{{ bill.data}}}
        </div>
        <div class="row"  v-if="logic.f_charge_type[0] !== '国税发票'" id="taxtestbill">
          {{{ taxbill.data}}}
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <div class="col-xs-5" v-if="messShow">
          <span style="color: red"><strong>未获取到收据代码，发票不能正常打印，请确认后补打发票</strong></span>
        </div>
        <div class="col-sm-2" v-if="!messShow">
          <span><strong>发票号:{{model.f_bill_id}}</strong></span>
        </div>
        <report-print v-if="logic.f_charge_type[0] === '国税发票'" id='testbill' top='25mm' left='60mm' width='100%' height='80%' style='td,th{font-size: 10pt!important;}'
        :notrepeat="true" v-if= 'bill.data && model.f_bill_id'></report-print>
        <report-print v-if="logic.f_charge_type[0] !== '国税发票'" id='taxtestbill' top='25mm' left='60mm' width='100%' height='80%' style='td,th{font-size: 10pt!important;}'
        :notrepeat="true" v-if= 'bill.data && model.f_bill_id'></report-print>
        <!-- <button class="btn btn-default" @click="confirm()">打印</button> -->
        <button type="button" class="btn btn-default" @click='cancel()' id="common-priOthChaBill-取消">取消</button>
      </footer>
    </modal>
  </div>
</template>
<script>
import * as Util from '../../../components/Util'
import { DataModel } from 'vue-client'
export default {
  title: '其他收费发票',
  data () {
    return {
      model: {
        f_bill_id: ''
      },
      bill: new DataModel('rs/report/other_bill'),
      taxbill: new DataModel('rs/report/tax_other_bill'),
      messShow: false
    }
  },
  props: ['show', 'row', 'logic'],
  watch: {
    'show' (val) {
      if (val === true) {
        this.getBillNum(this.logic.f_charge_type[0])
      }
    }
  },
  methods: {
    cancel  () {
      this.$dispatch('toggle')
    },
    getBillNum (type) {
      let tablename = 't_billcollec'
      let condition = 'f_user = ' + "'" + Util.f.name + "'" + ' and f_bill_state = ' + "'" + '启用' + "'" + ' and f_bill_type = ' + "'" + '国税发票' + "'"
      this.$SqlService.singleTable(tablename, condition).then((res) => {
        if (res.data[0]. f_bill_id > res.data[0].f_end_number) {
          res.data[0]. f_bill_state = '停用'
          this.$BillService.stopBill(res.data[0])
          this.messShow = true
        } else {
          this.model.f_bill_id = res.data[0].f_bill_id
          this.model.f_billcoll_id = res.data[0].id
        }
      }).catch((error) => {
        this.messShow = true
      })
    }
    // confirm () {
    //   this.$PrintService.modifyBillNumber(this.model, this.data).then((res) => {
    //     this.$dispatch('success', '发票打印', this.data, res)
    //   }).catch((error) => {
    //     this.$dispatch('error', '发票打印', this.data, error)
    //   })
    // }
  },
  events: {
    'print-success' () {
      this.row = Object.assign({}, this.row, this.logic)
      this.$PrintService.modifyBillNumber(this.model, this.row).then((res) => {
        this.$dispatch('success')
      }).catch((error) => {
        this.$dispatch('error', '发票打印', this.row, error)
      })
    },
    'print-error' () {
      this.$dispatch('error', '发票打印', this.row, null)
    }
  }
}

</script>
<style >
</style>
